package com.store.controller;

import com.store.service.ForeService;
import com.store.service.UserService;
import com.store.utils.JsonResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
@RequestMapping("/fore")
public class ForeController {

    @Autowired
    private ForeService foreService;

    @Autowired
    private UserService userService;

    /**
     * 首页展示
     */
    @RequestMapping("/toIndex")
    public String toIndex(Model model){
        return foreService.findAllCategory(model);
    }

    /**
     * 点击轮播图中的产品，去产品详细页面
     */
    @RequestMapping("/showProductByPid")
    public String showProductByPid(Integer pid, Model model){
        return foreService.findProductByPid(pid, model);
    }

    /**
     * 注册页面
     */
    @RequestMapping("/toRegister")
    public String toRegister() {
        return "/forepage/foreRegister";
    }
    /**
     * 检查username
     */
    @RequestMapping("/toCheckUsername")
    @ResponseBody
    public JsonResult toCheckUsername(String username) {
        return userService.findUserByUsername(username);
    }

    /**
     * 注册
     */
    @RequestMapping("/doRegister")
    public String doRegister() {
        return "";
    }

    /**
     * 登录
     */

}
